package com.whj.controller;

import com.whj.domain.dto.LoginUserDTO;
import com.whj.domain.entity.User;
import com.whj.domain.enums.AppHttpCodeEnum;
import com.whj.domain.response.ResponseResult;
import com.whj.exception.SystemException;
import com.whj.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther: wanghaijun
 * @Date: 2023/5/23 - 05 - 23 - 14:56 
 * @Description: com.whj.controller
 */

@RestController
public class BlogLoginController {

    @Autowired
    private LoginService loginService;

    /**
     * 用户登录
     *
     * @param loginUserDTO
     * @return
     */
    @PostMapping("/login")
    public ResponseResult login(@RequestBody LoginUserDTO loginUserDTO) {

        if (!StringUtils.hasText(loginUserDTO.getUserName())) {
            throw new SystemException(AppHttpCodeEnum.REQUIRE_USERNAME);
        }
        return loginService.login(loginUserDTO);

    }

    @PostMapping("/logout")
    public ResponseResult logout(){
        return loginService.logout();
    }
}
